﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ModeloGaleriaNET
{
    public class Validacion
    {
        public static bool NIF(string nif)
        {
            bool validar = false;
            String letras = "TRWAGMYFPDXBNJZSQVHLCKE";

            if (nif.Length == 9 && Regex.IsMatch(nif, @"^[0-9]{8}[A-Z]{1}$") && nif[8] == letras[int.Parse(nif.Substring(0, 8)) % 23])
                validar = true;

            return validar;
        }

        public static bool CIF(string cif)
        {
            bool validar = false;

            if (cif.Length == 9 && Regex.IsMatch(cif, @"^[ABCDEFGHJNPQRSUVW]{1}[0-9]{8}$"))
                validar = true;

            return validar;
        }

        public static bool Password(string pass)
        {
            return (Regex.IsMatch(pass, @"^[A-Za-z0-9_]{6,16}$")
                && Regex.IsMatch(pass, @"[A-Z]+")
                && Regex.IsMatch(pass, @"[a-z]+")
                && Regex.IsMatch(pass, @"[0-9]+")
                || Validacion.NIF(pass));
        }

        public static bool Telefono(string telefono)
        {
            return Regex.IsMatch(telefono, @"^[0-9]{9}$");
        }

        public static bool Email(string email)
        {
            return Regex.IsMatch(email, @"^[A-Za-z0-9\-\._]+@([a-z]+\.)+[a-z]{2,4}$");
        }

        public static bool Fecha(DateTime fecha)
        {
            return fecha.Date < DateTime.Now.Date;
        }

        public static bool IsPositiveInteger(string cadena)
        {
            try
            {
                Convert.ToInt32(cadena);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
